from sklearn.cluster import DBSCAN
from sklearn.datasets import make_moons
import matplotlib.pyplot as plt

# 数据集
X, y = make_moons(n_samples=200, noise=0.05, random_state=0)

# DBSCAN聚类
dbscan = DBSCAN(eps=0.2, min_samples=5)
clusters = dbscan.fit_predict(X)

# 绘图聚类
plt.scatter(X[:, 0], X[:, 1], c=clusters, s=50, cmap='viridis');
plt.show()
